import { createRouter, createWebHistory, createWebHashHistory } from "vue-router";
import Login from '../views/login/Login.vue'
import Main from '../views/main/Main.vue'
import ShowCenter from '../views/showcenter/ShowCenter.vue'
import Host from '../views/host/Host.vue'
import Console from '../views/host/Console.vue' 
import Test from '../views/Test.vue'
import Result from '../views/Result.vue'
import Crond from '../views/crond/Crond.vue'
import MultiExec from '../views/tasks/MultiTasksExec.vue'
import MultiScripts from '../views/tasks/MultiScriptsExec.vue'
import ssh from '../views/terminal/SSHTerminal.vue'
import UserLoginRecord from '../views/user/UserLoginRecord.vue'
import store from "../store"
import axios from "axios"
import settings from "../settings.js";
//import Home from "../views/Home.vue";


var children_route_showCenter = {
	meta: {
		title: '展示中心',
		authenticate: false,
	},
	path: 'showCenter',
	name: 'ShowCenter',
	component: ShowCenter
}

var children_route_host = {
	meta: {
		title: '资产管理',
		authenticate: false,
	},
	path: 'host',
	name: 'Host',
	component: Host
}

var children_route_crond = {
	meta: {
		title: '定时计划',
		authenticate: false,
	},
	path: 'crond',
	name: 'Crond',
	component: Crond
}

var children_route_console = {
	meta: {
		title: 'Console',
		authenticate: false,
	},
	path: 'console/:host_id',
	name: 'Console',
	component: Console
}

var children_route_multi_exec = {
	meta: {
		title: '批量任务执行',
		authenticate: false,
	},
	path: 'multi_exec',
	name: 'MultiExec',
	component: MultiExec,
}

var children_route_multi_scripts_exec = {
	meta: {
		title: '批量脚本执行',
		authenticate: false,
	},
	path: 'multi_scripts_exec',
	name: 'MultiScripts',
	component: MultiScripts,
}

var children_route_userloginrecord = {
	meta: {
		title: '登录日志',
		authenticate: false,
	},
	path:"userloginrecord",
	name:"userloginrecord",
	component: UserLoginRecord
}

var route_login = {
	meta: {
		title: '账户登录',
		authenticate: false,
	},
	path:"/login",
	name:"Login",
	component: Login
}

var route_test = {
	meta: {
		title: '测试页面',
		authenticate: false,
	},
	path:"/test",
	name:"Test",
	component: Test
}

var route_result = {
	meta: {
		title: '结果验证界面',
		authenticate: false,
	},
	path:"/result",
	name:"Result",
	component: Result
}

var route_ssh = {
	meta: {
		title: '结果验证界面',
		authenticate: false,
	},
	path:"/ssh",
	name:"ssh",
	component: ssh
}

var route_main = {
	meta: {
		title: '运维平台',
		authenticate: false,
	},
	path: '/main',
	alias: '/',
	name: 'main',
	component: Main,
	children: [
		children_route_showCenter,
		children_route_host,
		children_route_crond,
		children_route_console,
		children_route_multi_exec,
		children_route_multi_scripts_exec,
		children_route_userloginrecord,
	]
}

const routes = [
	route_login,
	route_test,
	route_result,
	route_ssh,
	route_main,
];

const router = createRouter({
	// history: createWebHistory(),
	history: createWebHashHistory(),
	routes,
});

router.beforeEach((to, from, next) => {
    document.title = to.meta.title;
    // console.log("to", to)
    // console.log("from", from)
    // console.log("store.getters.token:", store.getters.token)
	console.log("store.getters.token:", store.getters.token)
	console.log(settings);

    if (to.path !== '/login' && store.getters.token === "") {
		return next('/login')
    } else {
		return next()
	}
	
});


export default router;
